/**
 * @author Maximilian Csuk
 * @author Bernhard Denner
 * @author Konrad Paumann
 */

import java.util.Random;

public class IntBinTreeInserter implements Runnable {
	private BinTree<MyInteger> t;
	private int incCount; // number of times node was incremented
	private int createCount; // number of times node was created
	private OutputHandler out;
	private int id;

	public IntBinTreeInserter(BinTree<MyInteger> t, OutputHandler o, int id) {
		this.t = t;
		this.incCount = this.createCount = 0;
		out = o;
		this.id = id;
	}
	/**
	 * Inserts 10000 MyIntegers in the tree
	 * and then writes statistics of the operation to the output
	 */
	public void run() {
		for(int i = 0;i < 10000;i++) {
			int k = new Random().nextInt(100);
			boolean r = t.insert(new MyInteger(k));
			if (r)
				createCount++;
			else
				incCount++;
		}
		out.print("Inserter " + id + " finished...  " + 
				createCount + " nodes created, " +
				incCount + " nodes incremented");
	}
}
